package com.bw.produce.controller;

import com.bw.common.core.domain.R;
import com.bw.common.core.utils.StringUtils;
import com.bw.common.core.utils.poi.ExcelUtil;
import com.bw.common.core.web.domain.AjaxResult;
import com.bw.common.core.web.controller.BaseController;
import com.bw.common.core.web.page.TableDataInfo;
import com.bw.common.log.annotation.Log;
import com.bw.common.log.enums.BusinessType;
import com.bw.common.security.annotation.InnerAuth;
import com.bw.common.security.annotation.RequiresPermissions;
import com.bw.common.security.utils.SecurityUtils;
import com.bw.produce.domain.Brand;
import com.bw.produce.query.BrandQueryObject;
import com.bw.produce.service.IBrandService;
import com.bw.system.api.domain.SysDept;
import com.bw.system.api.domain.SysFile;
import com.bw.system.api.domain.SysRole;
import com.bw.system.api.domain.SysUser;
import com.bw.system.api.model.LoginUser;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;


/**
 * @author lemon
 * @date 2024/11/12 21:37
 **/
@RestController
@RequestMapping("/brand")
public class BrandController extends BaseController{

    @Autowired
    private IBrandService brandService;


    /**
     * 图片上传
     */
    @PostMapping("upload")
    public AjaxResult upload(MultipartFile file) {
         R<SysFile> upload = brandService.upload(file);
        return AjaxResult.success(upload.getData());
    }


    /**
     * 根据参数编号获取详细信息
     */
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable Long brandId)
    {
        return success(brandService.getInfo(brandId));
    }

    /**
     * 获取品牌列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BrandQueryObject queryParams){
        startPage();
        List<Brand> list = brandService.selectBrandList(queryParams);
        return getDataTable(list);
    }


    /**
     * 新增品牌
     */
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Brand brand) {
        brandService.insertBrand(brand);
        return toAjax(true);
    }

    /**
     * 修改是否制造商
     */
    @PutMapping("/changeManufacturer/{brandId}")
    public AjaxResult changeManufacturer(@PathVariable Long brandId) {
        brandService.changeManufacturer(brandId);
        return toAjax(true);
    }

    /**
     * 修改是否显示
     */
    @PutMapping("/changeReveal/{brandId}")
    public AjaxResult changeReveal(@PathVariable Long brandId) {
        brandService.changeReveal(brandId);
        return toAjax(true);
    }


    /**
     * 修改品牌
     */
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Brand brand) {
        brandService.updateBrand(brand);
        return toAjax(true);
    }

    /**
     * 删除品牌
     */
    @DeleteMapping("/{brandId}")
    public AjaxResult remove(@PathVariable Long[] brandId) {
        brandService.deleteBrandById(brandId);
        return toAjax(true);
    }

}
